home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / extmath.zip / EXTMUL.S < prev    next >
Text File  |  1993-01-06  |  2KB  |  119 lines

  1. ; Unsigned multiply of two 64-bit numbers
  2. ;
  3. ; Tim Victor, January 5, 1993
  4. ;
  5. ; Callable from C as follows:
  6. ; int ExtMul(src, dest);
  7. ;   always return 0
  8. ;
  9.         .model  small
  10.         .code
  11.         public _ExtMul
  12. _ExtMul proc near
  13.  
  14.         push bp         ; save caller's stack frame
  15.         mov  bp,sp      ; address stack frame of this call
  16.         sub  sp,8       ; store temp result on stack
  17.         push si
  18.         push di
  19.  
  20.         mov  si,[bp+4]          ; source address
  21.         mov  di,[bp+6]          ; dest address
  22.  
  23. ; multiply dest[0] * src
  24.         mov  ax,[si]
  25.         mul  word ptr [di]
  26.         mov  [bp-8],ax
  27.         mov  bx,dx
  28.  
  29.         mov  ax,[si+2]
  30.         mul  word ptr [di]
  31.         add  ax,bx
  32.         adc  dx,0
  33.         mov  [bp-6],ax
  34.         mov  bx,dx
  35.  
  36.         mov  ax,[si+4]
  37.         mul  word ptr [di]
  38.         add  ax,bx
  39.         adc  dx,0
  40.         mov  [bp-4],ax
  41.         mov  bx,dx
  42.  
  43.         mov  ax,[si+6]
  44.         mul  word ptr [di]
  45.         add  ax,bx
  46.         adc  dx,0
  47.         mov  [bp-2],ax
  48.  
  49. ; result += dest[1] * src
  50.         mov  ax,[si]
  51.         mul  word ptr [di+2]
  52.         add  ax,[bp-6]
  53.         adc  dx,0
  54.         mov  [bp-6],ax
  55.         mov  bx,dx
  56.  
  57.         mov  ax,[si+2]
  58.         mul  word ptr [di+2]
  59.         add  ax,bx
  60.         adc  dx,0
  61.         add  ax,[bp-4]
  62.         adc  dx,0
  63.         mov  [bp-4],ax
  64.         mov  bx,dx
  65.  
  66.         mov  ax,[si+4]
  67.         mul  word ptr [di+2]
  68.         add  ax,bx
  69.         adc  dx,0
  70.         add  ax,[bp-2]
  71.         adc  dx,0
  72.         mov  [bp-2],ax
  73.  
  74. ; result += dest[2] * src
  75.         mov  ax,[si]
  76.         mul  word ptr [di+4]
  77.         add  ax,[bp-4]
  78.         adc  dx,0
  79.         mov  [bp-4],ax
  80.         mov  bx,dx
  81.  
  82.         mov  ax,[si+2]
  83.         mul  word ptr [di+4]
  84.         add  ax,bx
  85.         adc  dx,0
  86.         add  ax,[bp-2]
  87.         adc  dx,0
  88.         mov  [bp-2],ax
  89.  
  90. ; result += dest[3] * src
  91.         mov  ax,[si]
  92.         mul  word ptr [di+6]
  93.         add  ax,[bp-2]
  94.         adc  dx,0
  95.         mov  [bp-2],ax
  96.  
  97. ; copy result to dest
  98.         mov  ax,[bp-8]
  99.         mov  [di],ax
  100.         mov  ax,[bp-6]
  101.         mov  [di+2],ax
  102.         mov  ax,[bp-4]
  103.         mov  [di+4],ax
  104.         mov  ax,[bp-2]
  105.         mov  [di+6],ax
  106.  
  107.         sub  ax,ax      ; return 0
  108.  
  109.         pop  di
  110.         pop  si
  111.         mov  sp,bp
  112.         pop  bp
  113.  
  114.         ret
  115.  
  116. _ExtMul endp
  117.         end
  118.  
  119.